package org.springframework.prospring.ticket.service.impl;

import org.springframework.prospring.ticket.service.SurfaceTypeManager;
import org.springframework.prospring.ticket.dao.SurfaceTypeDAO;
import org.springframework.prospring.ticket.domain.SurfaceType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Collection;

public class SurfaceTypeManagerImpl implements SurfaceTypeManager {
    private static Log logger = LogFactory.getLog(SurfaceTypeManagerImpl.class);
    private SurfaceTypeDAO dao;

    public SurfaceTypeManagerImpl() {
        super();
        if (logger.isDebugEnabled()) {
            logger.debug("in SurfaceTypeManagerImpl Constructor");
        }
    }

    public void setSurfaceTypeDAO(SurfaceTypeDAO dao) {
        if (logger.isDebugEnabled()) {
            logger.debug("setting SurfaceTypeDAO: " + dao);
        }

        this.dao = dao;
    }

    public SurfaceType findSurfaceType(Long surfaceTypeId){
        if (logger.isDebugEnabled()) {
            logger.debug("finding all SurfaceTypes ");
        }

        SurfaceType surfaceType = dao.findSurfaceType(surfaceTypeId);

        if (surfaceType == null) {
            logger.warn("Not found any SurfaceType in database with id="+surfaceTypeId);
        }

        return surfaceType;
    }

    public Collection<SurfaceType> findAllSurfaceTypes(){
        if (logger.isDebugEnabled()) {
            logger.debug("finding all SurfaceTypes ");
        }
        Collection<SurfaceType> surfaceTypes = dao.findAllSurfaceTypes();

        if (surfaceTypes == null) {
            logger.warn("Not found any SurfaceTypes in database.");
        }

        return surfaceTypes;
    }


    public SurfaceType saveSurfaceType(SurfaceType surfaceType) throws Exception {
        if (logger.isDebugEnabled()) {
            logger.debug("saving SurfaceType: " + surfaceType);
        }

        dao.saveSurfaceType(surfaceType);

        return surfaceType;
    }

    public void removeSurfaceType(Long surfaceTypeId) {
        dao.removeSurfaceType(surfaceTypeId);
    }


}
